;; insert quads' angles between start and end angles
(defun insert-rad (x y)
  (vl-load-com)
  (if (> x y)
    (setq y (+ y (* 2.0 pi)))
  )
  (vl-remove-if
    '(lambda (z)
       (if (>= y z)
	 nil
	 t
       )
     )
    (vl-remove-if
      '(lambda (z)
	 (if (<= x z)
	   nil
	   t
	 )
       )
      (vl-sort (list x y 0.0 (* pi 0.5) pi (* pi 1.5) (* pi 2.0)) '<) ; VERY BUGGY, FIX IT!!!
    )
  )
)
;; make pairs list from list
(defun make-pairs (x)
  (cond
    ((null x) nil)
    (t
     (progn
       (if (not (null (cadr x)))
	 (append (list (list (car x) (cadr x)))
		 (make-pairs (cdr x))
	 )
       )
     )
    )
  )
)
;; make arc entity
(defun make-arc	(anglist)
  (entmake (list
	     (cons '0 "ARC")
	     (cons '10 center)
	     (cons '40 rad)
	     (cons '50 (car anglist))
	     (cons '51 (cadr anglist))
	   )
  )
)
;; Break arc or circle
(defun break-arc (entity / ent center rad fangle eangle)
  (setq	ent    (entget entity)
	center (cdr (assoc 10 ent))
	rad    (cdr (assoc 40 ent))
	fangle (cdr (assoc 50 ent))
	eangle (cdr (assoc 51 ent))
  )
  (if (null fangle)
    (setq fangle 0)
  )
  (if (null eangle)
    (setq eangle (* 2.0 pi))
  )
  (mapcar 'make-arc (make-pairs (insert-rad fangle eangle)))
  (entdel entity)
)

;;; Break all arcs and circles in their quadrants
(defun c:quads (/ mustdie entity lasty)
  (setq mustdie (list "ARC" "CIRCLE"))
  (setq lasty (entlast))
  (setq entity (entnext))
  (while (not (equal entity lasty))
    (if	(member (cdr (assoc 0 (entget entity))) mustdie)
      (break-arc entity)
    )
    (setq entity (entnext entity))
  )
  (if (member (cdr (assoc 0 (entget entity))) mustdie)
    (break-arc entity)
  )

  (princ)
)

;;; Break one arc or circle in quadrants
(defun c:quads1	(/ mustdie entity)
  (setq	mustdie	(list "ARC" "CIRCLE")
	entity	(car (entsel))
  )
  (if (member (cdr (assoc 0 (entget entity))) mustdie)
    (progn
      (break-arc entity)
    )
  )
  (princ)
)